﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using WeatherReport.ViewModels;

namespace WeatherReport.UnitTests.ViewModels.ScrewViewModelTests
{
    [TestClass]
    public class RecalculateSlitCoordinates
    {
        private const double DELTA = 0.0001;

        [TestMethod]
        public void Given_Direction0Degrees()
        {
            const double SIZE = 100.0;
            double dir = 0.0;

            ScrewViewModel sut = new ScrewViewModel(SIZE);

            //--- Act
            sut.RecalculateSlitCoordinates(dir);

            //--- Assert
            double halfSize = SIZE / 2.0;
            double cathetus = halfSize / Math.Sqrt(2.0);
            Assert.AreEqual(halfSize, sut.SlitX1, DELTA, "Unexpected SlitX1");
            Assert.AreEqual(0.0, sut.SlitY1, DELTA, "Unexpected SlitY1");
            Assert.AreEqual(halfSize, sut.SlitX2, DELTA, "Unexpected SlitX2");
            Assert.AreEqual(SIZE, sut.SlitY2, DELTA, "Unexpected SlitY2");
        }

        [TestMethod]
        public void Given_DirectionPlus45Degrees()
        {
            const double SIZE = 100;
            double dir = Math.PI / 4.0;

            ScrewViewModel sut = new ScrewViewModel(SIZE);

            //--- Act
            sut.RecalculateSlitCoordinates(dir);

            //--- Assert
            double halfSize = SIZE / 2.0;
            double cathetus = halfSize / Math.Sqrt(2.0);
            Assert.AreEqual(halfSize + cathetus, sut.SlitX1, DELTA, "Unexpected SlitX1");
            Assert.AreEqual(halfSize - cathetus, sut.SlitY1, DELTA, "Unexpected SlitY1");
            Assert.AreEqual(halfSize - cathetus, sut.SlitX2, DELTA, "Unexpected SlitX2");
            Assert.AreEqual(halfSize + cathetus, sut.SlitY2, DELTA, "Unexpected SlitY2");
        }

        [TestMethod]
        public void Given_DirectionPlus90Degrees()
        {
            const double SIZE = 100.0;
            double dir = Math.PI / 2.0;

            ScrewViewModel sut = new ScrewViewModel(SIZE);

            //--- Act
            sut.RecalculateSlitCoordinates(dir);

            //--- Assert
            double halfSize = SIZE / 2.0;
            Assert.AreEqual(SIZE, sut.SlitX1, DELTA, "Unexpected SlitX1");
            Assert.AreEqual(halfSize, sut.SlitY1, DELTA, "Unexpected SlitY1");
            Assert.AreEqual(0.0, sut.SlitX2, DELTA, "Unexpected SlitX2");
            Assert.AreEqual(halfSize, sut.SlitY2, DELTA, "Unexpected SlitY2");
        }

        [TestMethod]
        public void Given_DirectionMinus90Degrees()
        {
            const double SIZE = 100.0;
            double dir = -Math.PI / 2.0;

            ScrewViewModel sut = new ScrewViewModel(SIZE);

            //--- Act
            sut.RecalculateSlitCoordinates(dir);

            //--- Assert
            double halfSize = SIZE / 2.0;
            Assert.AreEqual(0.0, sut.SlitX1, DELTA, "Unexpected SlitX1");
            Assert.AreEqual(halfSize, sut.SlitY1, DELTA, "Unexpected SlitY1");
            Assert.AreEqual(SIZE, sut.SlitX2, DELTA, "Unexpected SlitX2");
            Assert.AreEqual(halfSize, sut.SlitY2, DELTA, "Unexpected SlitY2");
        }
    }
}
